package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysRole;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FhSchoolDept;
import com.ruoyi.system.service.IFhSchoolDeptService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 部门Controller
 * 
 * @author ruoyi
 * @date 2025-03-25
 */
@Controller
@RequestMapping("/system/fhSchoolDept")
public class FhSchoolDeptController extends BaseController
{
    private String prefix = "system/dept";

    @Autowired
    private IFhSchoolDeptService fhSchoolDeptService;

    @RequiresPermissions("system:dept:view")
    @GetMapping()
    public String dept()
    {
        return prefix + "/dept";
    }

    /**
     * 导出部门列表
     */
    @RequiresPermissions("system:dept:export")
    @Log(title = "部门", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FhSchoolDept fhSchoolDept)
    {
        List<FhSchoolDept> list = fhSchoolDeptService.selectFhSchoolDeptList(fhSchoolDept);
        ExcelUtil<FhSchoolDept> util = new ExcelUtil<FhSchoolDept>(FhSchoolDept.class);
        return util.exportExcel(list, "部门数据");
    }

    /**
     * 新增部门
     */
    @RequiresPermissions("system:dept:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存部门
     */
    @RequiresPermissions("system:dept:add")
    @Log(title = "部门", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FhSchoolDept fhSchoolDept)
    {
        return toAjax(fhSchoolDeptService.insertFhSchoolDept(fhSchoolDept));
    }

    /**
     * 修改部门
     */
    @RequiresPermissions("system:dept:edit")
    @GetMapping("/edit/{deptId}")
    public String edit(@PathVariable("deptId") Long deptId, ModelMap mmap)
    {
        FhSchoolDept fhSchoolDept = fhSchoolDeptService.selectFhSchoolDeptByDeptId(deptId);
        mmap.put("fhSchoolDept", fhSchoolDept);
        return prefix + "/edit";
    }

    /**
     * 修改保存部门
     */
    @RequiresPermissions("system:dept:edit")
    @Log(title = "部门", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FhSchoolDept fhSchoolDept)
    {
        return toAjax(fhSchoolDeptService.updateFhSchoolDept(fhSchoolDept));
    }

    /**
     * 删除部门
     */
    @RequiresPermissions("system:dept:remove")
    @Log(title = "部门", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fhSchoolDeptService.deleteFhSchoolDeptByDeptIds(ids));
    }

    /**
     * 加载部门列表树
     */
    @RequiresPermissions("system:dept:fhSchoolDeptTree")
    @GetMapping("/FhSchoolDeptTreeData")
    @ResponseBody
    public List<Ztree> deptTreeData()
    {
        List<Ztree> ztrees = fhSchoolDeptService.selectFhSchoolDeptTree(new FhSchoolDept());
        return ztrees;
    }
}
